package com.situ.onlinebookstore.common.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.situ.onlinebookstore.common.Validation.ValidationType;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Date;

@Data
@NoArgsConstructor
@ToString
public class User {
    public static final int STATUS_ENABLE = 0;
    public static final int STATUS_DISABLE = 1;


    private Integer id;
    @Pattern(regexp = "^[a-zA-Z0-9]{3,16}$",
            message = "账号必须是3-16位的字符串",
            groups = ValidationType.Login.class)
    private String username;
    @Pattern(regexp = "^[a-zA-Z0-9]{3,16}$",
            message = "账号必须是3-16位的字符串",
            groups = {ValidationType.Login.class, ValidationType.SetPayPassword.class})
    private String password;
    private String salt;
    private String phone;
    private String email;
    private String name;
    private String sex;
    @JsonFormat(pattern = "yyyy年MM月dd日 HH:mm:ss", timezone = "GMT-8")
    private Date birthday;
    private String idcard;
    private BigDecimal money;
    @NotNull(message = "支付密码不能为空",
            groups = ValidationType.SetPayPassword.class)
    @Pattern(regexp = "^[0-9]{6}$", message = "支付密码必须是六位数字",
            groups = ValidationType.SetPayPassword.class)
    private String payPassword;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    private LocalDateTime createTime;
    private String avatar;
    private Integer status;

}
